define(function(require, exports){
	var $ = require('jquery');
	var pubjs = require('pubjs');
	var grid = require('@base/highGrid');
	var util = require('util');
	var tip = require('@base/tip');

	var Base = grid.base.extend({
		init: function(config){
			config = pubjs.conf(config, {
				url: 'materialGroup/list',
				cols: [],
				param: {
					order: '_id|-1'
				},
				tip: {
					"pos": "mr",
					"width": 720,
					'autoShow': false,
					'gridMod': "materialGroup/modules/edit.base",
					'grid': null,
				},
				hasDetail: true,
				hasBatch: true,
				hasMenu: true,
				hasFresh: true,
				hasSearch: true,
				hasTab: false,
				hasAmount: false,
				hasFilter: false,
				hasExport: false,
				hasSelect: true,
				reqType: 'websocket',
				gridName: 'condition'
			});
			this.Super('init', arguments);
		},
		afterBuild: function () {
			var self = this;
			self.Super('afterBuild', arguments);
			var c = this.getConfig();
			if(c.hasDetail)
			{
				self.$tip = c.tip;
				var mod = self.$tip.mod = self.create('tip', tip.base, util.extend({}, c.tip, {
					"data": [
						'<div class ="P-campaignDiagnosisTipTitle pb10" />',
						'<div class="P-campaignDiagnosisTipWrap"/>'
					].join(''),
					'autoHide': 'leave'
				}));

				// 构建tip内容
				mod.setData(mod.getConfig('data'));
				mod.css('display', 'none');
				self.$tip.titleEl = mod.find('.P-campaignDiagnosisTipTitle');
				// 创建表格
				mod.createAsync('grid', self.$tip.gridMod, {
					hideMethod: true,
					target: mod.find('.P-campaignDiagnosisTipWrap'),
					wrapperClass: 'P-campaignDiagnosisTipWrap'
				}, function (mod) {
					self.$tip.grid = mod;
				});
			}
		},
		renderStrategy: function(index, val, data) {
			var sids = [];
			var wids = [];
			util.each(data.Strategy, function (strategy) {
				sids.push.apply(sids, strategy.SweetyIds);
				wids.push.apply(wids, strategy.WhiskyIds);
			});
			var html = $(`
				<div data-id="${data._id}">
					${LANG('创意包(%1)', sids.length)}, ${LANG('落地页(%1)', wids.length)}
				</div>
			`);

			if(this.getConfig('hasDetail'))
			{
				this.uiBind(html, 'mouseenter mouseleave', this.eventShowTip);
			}

			return html;
		},
		eventShowTip: function(ev, elm) {
			var $elm = $(elm);
			var id = $elm.attr("data-id"); // 尺寸ID
			var data = this.getData(); // 表格数据
			var nowData = util.find(data.items, +id, '_id');
			if (ev.type === 'mouseenter') {
				this.$tip.mod.update({
					anchor: $elm
				}).show();
				if(this.$tip.grid)
				{
					this.$tip.grid.reset().hideMethod().setData(nowData.StrategyInfo);
				}
			}
			return false;

		}
	});

	exports.base = Base;
});